<template>
  <div>
    <el-table
      :data="department"
      border
      stripe
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180"
        row-class-name="">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column>
      <el-table-column
        prop="eamil"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
    </el-table>
    <!-- 分页-->
    <el-pagination
      :page-sizes="[5, 10, 15, 20]"
      align="right"
      background
      layout="sizes,prev, pager,next"
      :total="total"
      :page-size="pageSize"
      :current-page="crrentPage"
      @current-change="goCurrentPage"
      @size-change="goPageSize">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'Department',
  data () {
    return {
      department:[],
      total:0,
      crrentPage:1,
      pageSize:5,
    }
  },
  // 在钩子函数中调用查询方法
  mounted() {
    this.list();
  },
  methods:{
    goCurrentPage(crrentPage){
      // 先赋值给data中的数据
      this.currentPage = crrentPage;
      // 调用查询方法
      this.list();
    },
    goPageSize(pageSize){
      // 先赋值给data中的数据
      this.pageSize = pageSize;
      // 调用查询方法
      this.list();
    },
    list(){
      // 发送ajax请求
      this.$http.get("/department/queryDepa",{"crrentPage":this.currentPage,"pageSize":this.pageSize})
          // 接收返回值对其操作
        .then(result=>{
          // 给department赋值查询到的数据
          this.department = result.data.data;
          this.total = result.data.totals;
        })
        // 有异常情况时
        .catch(error=>{
          alert("系统繁忙中")
          console.log(error)
        })
    }
  }

}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
